package com.sunny.shop.repository;

import com.sunny.shop.model.Category;
import com.sunny.shop.model.Collect;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;

public interface CollectRepository extends JpaRepository<Collect,Long> {
    Collect findOneByCollectTypeAndTopicIdAndUid(Integer collectType, Long topicId, Long uid);
    Collect findOneByTopicIdAndUid(Long topicId, Long uid);
    @Modifying
    @Transactional
    @Query("update Collect as c set c.status = :status where c.collectType = :collectType and c.topicId = :topicId and c.uid = :uid")
    Integer updateStatus(Integer status, Integer collectType, Long topicId, Long uid);

    @Query(value = "select c.topicId from Collect as c where c.uid = :uid and c.collectType = :collectType and c.status = :status")
    ArrayList<Long> selectorderby(Long uid, Integer collectType, Integer status);
}
